<?php

namespace app\common\model\driving;

use think\Model;

/**
 * 司机模型
 */
class Driver extends Model
{





    // 表名
    protected $name = 'driving_driver';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];


    /**
     * 获取头像
     * @param string $value
     * @param array $data
     * @return string
     */
    public function getAvatarAttr($value, $data)
    {
        return cdnurl($value, true);
    }

    protected static function init()
    {
        self::beforeInsert(function ($row) {
            $changed = $row->getChangedData();
        });

        self::beforeUpdate(function ($row) {
            $changed = $row->getChangedData();
        });

        self::afterInsert(function ($row) {
            $changed = $row->getChangedData();
        });

        self::afterUpdate(function ($row) {
            $changed = $row->getChangedData();
        });
    }

    // 关联司机定位
    public function driverLocation(){
        return $this->hasOne(DriverLocation::class,'driver_id','id');
    }

}
